from collections import deque
def isonediff(str1, str2):
    count = 1
    for i in range(len(str1)):
        if str1[i] == str2[i]:
            count += 1
    return count == len(str1)
    

def main():
    N = int(input())
    
    startStr, endStr = map(str, input().split())
    
    strList = []
    for i in range(N):
        strList.append(str(input()))
    
    if startStr == endStr:
        print(0)
        return 0

    
    visited = [False] * N
    queue = deque()
    queue.append((startStr, 1))
    
    while queue:
        str1, step = queue.popleft()
        if isonediff(str1, endStr):
            print(step+1)
            return step+1
        
        for i in range(N):
            if not visited[i] and isonediff(str1, strList[i]):
                visited[i] = True
                queue.append((strList[i], step+1))
    
        
    print(0)
    return 0
    
main()